package cn.bluech.template.ui.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment

/**
 * Description: 不带设计模式的基类，主要用于没有交互/数据展示的包装控件
 * Date: 2020/8/11.
 */
abstract class BaseFmt : Fragment(){
    private var rootView : View? = null
    private var isFirstLoad = false

    abstract fun getLayout():Int
    abstract fun initView()
    abstract fun initData()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        rootView = View.inflate(activity,getLayout(),null)
    }

    override fun onCreateView(inflater: LayoutInflater,container: ViewGroup?,savedInstanceState: Bundle?): View? {
        return rootView
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView()
    }

    override fun onResume() {
        super.onResume()
        if(!isFirstLoad){
            isFirstLoad = true
            initData()
        }
        onShow()
    }

    open fun onShow(){
        // on fragment show
    }

    open fun onHide(){
        // on fragment hide
    }

}